public class Test1 {

    public static void main(String[] args) {
        Integer[] arrs = {-4, 1, 2, 2, 5, 5, 5, 8, 10};
        System.out.println( Search(arrs, 2));
    }


    public static int Search(Integer[] arrs, int value) {

        if (arrs.length == 0) {
            throw new IllegalArgumentException("数组不能为空");
        }

        if (arrs[arrs.length - 1] < value) {
            return arrs.length - 1;
        }

        int high = arrs.length - 1;

        int low = 0;


        //第一步
        while (low <= high) {

            int mid = low + ((high - low) >> 1);

            if (arrs[mid] > value) {

                high = mid - 1;

            } else {
                if (arrs[mid + 1] > value) {
                    return mid;
                } else {
                    low = mid + 1;
                }
            }
        }
        return -1;

    }


}

